package com.sf.ams.biz.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import com.sf.ams.biz.IDataStoreXmlAnalysisBiz;
import com.sf.ams.constant.Constant;
import com.sf.ams.entity.SystemInfo;
import com.sf.ams.saxhandler.DataStoreAnalysisHandler;
/**
 * 描述：
 * 
 * <pre>HISTORY
 * ****************************************************************************
 *  ID   DATE           PERSON          REASON
 *  1    2017-09-26      Simba.Hua         Create
 * ****************************************************************************
 * </pre>
 * @author Simba.Hua
 */
@Service("dataStoreXmlAnalysisBiz")
public class DataStoreXmlAnalysisBizImpl  implements IDataStoreXmlAnalysisBiz {
	@Override
	public List<SystemInfo> analysisDataStore() {
		return DataStoreAnalysisHandler.getInstance().getAllSystems();
	}
	@Override
	public SystemInfo getSystemBySystemCode(String systemCode,boolean showPassword) {
		List<SystemInfo> systems = analysisDataStore();
		if(systems == null || systems.isEmpty()){
			return null;
		}
		List<SystemInfo> selectSystem = systems.stream()
				.filter(s -> s.getSystemCode().equals(systemCode))
				.collect(Collectors.toList());
		if(selectSystem == null || selectSystem.isEmpty()) {
			return null;
		}
		SystemInfo systemInfo = selectSystem.get(0);
		if(showPassword){
			return systemInfo;
		}
		systemInfo.getEnvironments().forEach(e ->e.setDataBasePassword(Constant.PASSWORD_FLAG));
		return systemInfo;
	}
	
}
